#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
//    QMessageBox::information(this,//父对象
//                             "title",//标题
//                             "using QT");//内容
//    QMessageBox::aboutQt(this,"about QT");
//    QInputDialog::getText(this,"title","label");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
 QString filename =  QFileDialog:: getOpenFileName(this,//父对象
                                  "open file",//对话框标题
                                  QDir::currentPath(),//打开文件的路径
                                  "c++ source files(*.cpp *.c *.cxx);;c++ header files(*.h)"//过滤器
                                  );
 if(filename.isEmpty()){
     return;
 }
 qDebug() << filename;
}

void Widget::on_pushButton_2_clicked()
{
     QString fileName = QFileDialog::getSaveFileName(this,"save file",QDir::currentPath(),"c++ source files(*.cpp *.c *.cxx);;c++ header files(*.h)");
     if(fileName.isEmpty()){
          return;
      }
      qDebug() << fileName;

}

void Widget::on_pushButton_3_clicked()
{
  QColor color =  QColorDialog::getColor(Qt::green,//初始颜色
                           this,//父对象
                           "get color"//标题

                           );//获取颜色
    qDebug()<< color.red();//R分量
    qDebug()<< color.green();//G分量
    qDebug ()<<color.blue();//B分量
    ui->frame->setAutoFillBackground(true);
    ui->frame->setPalette(QPalette(color));
}

void Widget::on_pushButton_4_clicked()
{
    bool ok;
   QFont font =  QFontDialog::getFont(&ok,
                          QFont("Arial"),  //初始字体
                         this,//父对象
                         "tile"//标题
                         );//获取字体
    if(ok) ui->label->setFont(font);
}

void Widget::on_pushButton_5_clicked()
{
    myDialog log;
   // log.exec();//循环接受界面的事件并处理，槽函数尽量不做耗时操作
    if(log.exec() == QDialog::Accepted){
        qDebug()<<"accepted";
    }else{
        qDebug()<<"rejected";
    }
}
